home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Constructing and Drawing Paths / Filling Open Figures / GDITEST6.dpr
Encoding:
Text File  |  2003-10-15  |  2.6 KB  |  106 lines

  1. program GDITEST6;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   path: TGPGraphicsPath;
  14.   Pen: TGPPen;
  15.   brush : TGPSolidBrush;
  16. begin
  17.   graphics := TGPGraphics.Create(DC);
  18.  
  19.   path := TGPGraphicsPath.Create;
  20.  
  21.   // Add an open figure.
  22.   path.AddArc(0, 0, 150, 120, 30, 120);
  23.  
  24.   // Add an intrinsically closed figure.
  25.   path.AddEllipse(50, 50, 50, 100);
  26.  
  27.   pen := TGPPen.Create(MakeColor(128, 0, 0, 255), 5);
  28.   brush := TGPSolidBrush.Create(MakeColor(255, 255, 0, 0));
  29.  
  30.   // The fill mode is FillModeAlternate by default.
  31.   graphics.FillPath(brush, path);
  32.   graphics.DrawPath(pen, path);
  33.  
  34.   path.Free;
  35.   Pen.Free;
  36.   brush.Free;
  37.   graphics.Free;
  38. end;
  39.  
  40.  
  41. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  42. var
  43.   Handle: HDC;
  44.   ps: PAINTSTRUCT;
  45. begin
  46.   case message of
  47.     WM_PAINT:
  48.       begin
  49.         Handle := BeginPaint(Wnd, ps);
  50.         OnPaint(Handle);
  51.         EndPaint(Wnd, ps);
  52.         result := 0;
  53.       end;
  54.  
  55.     WM_DESTROY:
  56.       begin
  57.         PostQuitMessage(0);
  58.         result := 0;
  59.       end;
  60.  
  61.    else
  62.       result := DefWindowProc(Wnd, message, wParam, lParam);
  63.    end;
  64. end;
  65.  
  66. var
  67.   hWnd     : THandle;
  68.   Msg      : TMsg;
  69.   wndClass : TWndClass;
  70. begin
  71.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  72.    wndClass.lpfnWndProc    := @WndProc;
  73.    wndClass.cbClsExtra     := 0;
  74.    wndClass.cbWndExtra     := 0;
  75.    wndClass.hInstance      := hInstance;
  76.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  77.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  78.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  79.    wndClass.lpszMenuName   := nil;
  80.    wndClass.lpszClassName  := 'GettingStarted';
  81.  
  82.    RegisterClass(wndClass);
  83.  
  84.    hWnd := CreateWindow(
  85.       'GettingStarted',       // window class name
  86.       'Filling Open Figures',       // window caption
  87.       WS_OVERLAPPEDWINDOW,    // window style
  88.       Integer(CW_USEDEFAULT), // initial x position
  89.       Integer(CW_USEDEFAULT), // initial y position
  90.       Integer(CW_USEDEFAULT), // initial x size
  91.       Integer(CW_USEDEFAULT), // initial y size
  92.       0,                      // parent window handle
  93.       0,                      // window menu handle
  94.       hInstance,              // program instance handle
  95.       nil);                   // creation parameters
  96.  
  97.    ShowWindow(hWnd, SW_SHOW);
  98.    UpdateWindow(hWnd);
  99.  
  100.    while(GetMessage(msg, 0, 0, 0)) do
  101.    begin
  102.       TranslateMessage(msg);
  103.       DispatchMessage(msg);
  104.    end;
  105. end.
  106.